package org.metasketch.diagram.javafx.graphics;

import java.util.ArrayList;
import java.util.List;

import org.metasketch.graphics.Point;

import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.TextAlignment;

public class GraphicLinkNode extends Group {

	// Label nameLabel = new Label("Untitled");
	// Label identifierLabel = new Label("Untitled");
	Rectangle rect;// = new Rectangle();
	// protected int x;
	// protected int y;
	// protected int width;
	// protected int height;

	Color lineColor = Color.BLACK;
	// Color lightBackColor = Color.web("f5f5f5");
	// Color darkBackColor = Color.web("808080");

	int smallSquareSide = 10;
	List<Point> points = new ArrayList<Point>();

	public GraphicLinkNode(boolean execute, List<Point> points) {

		Line line = null;
		boolean started = false;
		for (Point point : points) {
			if (line == null) {
				line = new Line();
				// line.set
				line.setStroke(lineColor);
				line.setStrokeWidth(2);
				// line.toBack();
			}

			if (!started) {
				line.setStartX(point.getX());
				line.setStartY(point.getY());
				started = true;
			} else {
				line.setEndX(point.getX());
				line.setEndY(point.getY());
				started = false;
				getChildren().addAll(line);

				line = new Line();
				line.setStroke(lineColor);
				line.setStrokeWidth(2);
				line.setStartX(point.getX());
				line.setStartY(point.getY());
			}

		}

		if (execute) {
			Point point = points.get(points.size() - 1);
			rect = new Rectangle(0, 0, smallSquareSide, smallSquareSide);
			rect.setFill(lineColor);
			rect.setTranslateX(point.getX() - smallSquareSide / 2);
			rect.setTranslateY(point.getY() - smallSquareSide / 2);
			getChildren().addAll(rect);
		}
		// setTranslateX(x);
		// setTranslateY(y);
		// pane.set

		// Rectangle r = new Rectangle(width, height);
		// r.setTranslateX(gnode.getX());
		// r.setTranslateY(gnode.getY());
		// r.setFill(Color.BLUE);

		// Line line = new Line();
		// rect = new Rectangle(1, 1, width, height);
		// rect.setStroke(lineColor);
		// rect.setStrokeWidth(2);
		// rect.setFill(lightBackColor);

		// nameLabel.setStyle("-fx-background-color: #ff0000");

		// label.setStyle("-fx-background-color: #ff0000");
		// centerLabel();
		// line.getTransforms().add(Transform.translate(gnode.getX(),
		// gnode.getY()));
		// line.setTranslateX(gnode.getX());
		// line.setTranslateY(gnode.getY());

		// getChildren().add(r);
		// getChildren().add(line);

		// getChildren().addAll(line);
	}

}
